﻿using ESRI.ArcGIS.Geodatabase;
using System.Configuration;

namespace TubeBurstAnalysis
{
    internal class IShownValve
    {
        /// <summary>
        /// 对应地图元素
        /// </summary>
        public IFeature feature;

        /// <summary>
        /// 对象ID
        /// </summary>
        private int objectID;
        public int ObjectID
        {
            get => objectID;
            set => objectID = value;
        }

        /// <summary>
        /// X坐标
        /// </summary>
        private double x;
        public double X
        {
            get => x;
            set => x = value;
        }

        /// <summary>
        /// Y坐标
        /// </summary>
        private double y;
        public double Y
        {
            get => y;
            set => y = value;
        }


        /// <summary>
        /// 阀门标号
        /// </summary>
        private string name;
        public string Name
        {
            get => name;
            set => name = value;
        }

        /// <summary>
        /// 所属部门
        /// </summary>
        private string ownerDept;
        public string OwnerDept
        {
            get => ownerDept;
            set => ownerDept = value;
        }


        /// <summary>
        /// 勘测单位
        /// </summary>
        private string surveyDept;
        public string SurveyDept
        {
            get => surveyDept;
            set => surveyDept = value;
        }

        /// <summary>
        /// 阀门类型
        /// </summary>
        private string type;
        public string Type
        {
            get => type;
            set => type = value;
        }

        /// <summary>
        /// 维修次数
        /// </summary>
        private string repairCount;
        public string RepairCount
        {
            get => repairCount;
            set => repairCount = value;
        }


        public IShownValve(IFeature feature)
        {
            this.feature = feature;

            //获取相关属性在数据库中的字段
            string valveName = ConfigurationManager.AppSettings[0];
            string valveOwner = ConfigurationManager.AppSettings[1];
            string valveSurvey = ConfigurationManager.AppSettings[2];
            string valveType = ConfigurationManager.AppSettings[3];
            string valveRepairCount = ConfigurationManager.AppSettings[4];
            string objectID = ConfigurationManager.AppSettings[6];
            string x = ConfigurationManager.AppSettings[7];
            string y = ConfigurationManager.AppSettings[8];

            //根据字段查询相关属性
            this.objectID = (int)feature.get_Value(feature.Fields.FindField(objectID));
            this.x = (double)feature.get_Value(feature.Fields.FindField(x));
            this.y = (double)feature.get_Value(feature.Fields.FindField(y));
            name = feature.get_Value(feature.Fields.FindField(valveName)).ToString();
            ownerDept = feature.get_Value(feature.Fields.FindField(valveOwner)).ToString();
            surveyDept = feature.get_Value(feature.Fields.FindField(valveSurvey)).ToString();
            type = feature.get_Value(feature.Fields.FindField(valveType)).ToString();
            repairCount = feature.get_Value(feature.Fields.FindField(valveRepairCount)).ToString();
        }
    }
}
